package interceptor;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import entity.CroCustomer;
import org.apache.struts2.ServletActionContext;
import javax.servlet.ServletContext;

/**
 * Created by xuweijie on 17-5-3.
 * 前台自定义登录拦截器
 */
public class FrontLoginInterceptor extends AbstractInterceptor {
    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        ServletContext context= ServletActionContext.getServletContext();
        CroCustomer croCustomer= (CroCustomer) context.getAttribute("customer");
        if(croCustomer!=null){
            return actionInvocation.invoke();
        }else {
            return Action.LOGIN;
        }
    }
}
